<template>
  <div class="mvlist">
    <div class="title">
      <h1>热门MV</h1>
    </div>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li
          v-for="item in mvlistData"
          :key="item.content_id"
          @click="selectPlayList(item)"
        >
          <img :src="item.cover" alt="" />
          <span>{{ item.name }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";
import axios from "axios";

export default {
  data() {
    return {
      mvlistData: [],
    };
  },
  created() {
    this.mvlistData;
  },
  methods: {
    getMvList() {
      axios
        .get("api/top/mv?limit=6", "")
        .then((res) => {
          console.log(res.data.data);
          this.mvlistData = res.data.data;
          this.betterScrollHorizontal(this.mvlistData.length, 215);
        })
        .catch((err) => {
          console.error(err);
        });
    },
    betterScrollHorizontal(num, itemWidth) {
      let width = num * itemWidth;
      this.$refs.content.style.width = width + "px";
      this.$nextTick(() => {
        this.scroll = new BScroll(this.$refs.wrapper, {
          click: true,
          startX: 0,
          scrollX: true, //横向为true
          scrollY: false,
        });
      });
    },
    selectPlayList(item) {
      const id = item.id;
      const singerid=item.artistId;
      this.$router.push({
        name: "MvDetail",
        params: { id: id ,singerid:singerid},
      });
    },
  },
  mounted() {
    this.getMvList();
  },
  filters: {
    numFilter(value, num) {
      return parseFloat(value).toFixed(num);
    },
  },
};
</script>

<style scoped>
.mvlist {
  width: 94%;
  margin: 0 auto;
}
.title {
  text-align: left;
}
.title > h1 {
  display: inline-block;
  font-size: 18px;
  text-align: left;
}
.wrapper {
  width: 100%;
  overflow: hidden;
}
ul.content {
  text-align: left;
}
ul.content > li {
    text-align: left;
  width: 200px;
  display: inline-block;
  vertical-align: top;
  margin-right: 15px;
  cursor: pointer;
}
ul.content:nth-last-child(1) {
  margin-right: 0;
}
ul.content > li >img {
  width: 100%;
  border-radius: 10px;
}
ul.content > li >span {
  font-size: 14px;
}
</style>
